package org.blogwu.learn.multithread.chapter3.demo22;

public class Producer extends Thread {


    @Override
    public void run() {
        int i = 0;
        while (true) {
            boolean bb = true;
            while (bb) {
                if (Main.arrayBlockingQueue.offer(i + "")) {
                    System.out.println("放入值" + i + "成功");
                    bb = false;
                    i++;
                    break;
                }
                synchronized (Main.obj) {
                    System.out.println("Producer唤醒全部线程");
                    Main.obj.notifyAll();
                }
                try {
                    synchronized (Main.obj) {
                        System.out.println("Producer睡眠");
                        Main.obj.wait();
                    }

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
